package com.esri.android.map.ags;

import android.util.Log;
import android.webkit.MimeTypeMap;
import androidx.core.internal.view.SupportMenu;
import com.esri.android.map.GraphicsLayer;
import com.esri.android.map.event.OnStatusChangedListener;
import com.esri.android.map.popup.PopupLayer;
import com.esri.core.ags.LayerServiceCapabilities;
import com.esri.core.ags.LayerServiceInfo;
import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.MapGeometry;
import com.esri.core.geometry.Polygon;
import com.esri.core.geometry.SpatialReference;
import com.esri.core.internal.io.handler.n;
import com.esri.core.internal.tasks.TaskListener;
import com.esri.core.internal.tasks.ags.c.h;
import com.esri.core.internal.tasks.ags.i;
import com.esri.core.internal.tasks.ags.v;
import com.esri.core.internal.tasks.ags.w;
import com.esri.core.io.EsriSecurityException;
import com.esri.core.io.UserCredentials;
import com.esri.core.map.AttachmentInfo;
import com.esri.core.map.CallbackListener;
import com.esri.core.map.DrawingInfo;
import com.esri.core.map.EditFieldsInfo;
import com.esri.core.map.EditInfo;
import com.esri.core.map.Feature;
import com.esri.core.map.FeatureEditResult;
import com.esri.core.map.FeatureSet;
import com.esri.core.map.FeatureTemplate;
import com.esri.core.map.FeatureType;
import com.esri.core.map.FeatureUtil;
import com.esri.core.map.Field;
import com.esri.core.map.Graphic;
import com.esri.core.map.GraphicsUtil;
import com.esri.core.map.OwnershipBasedAccessControlForFeatures;
import com.esri.core.map.TimeAwareLayer;
import com.esri.core.map.TimeExtent;
import com.esri.core.map.TimeInfo;
import com.esri.core.map.popup.PopupFieldInfo;
import com.esri.core.map.popup.PopupInfo;
import com.esri.core.renderer.ClassBreaksRenderer;
import com.esri.core.renderer.Renderer;
import com.esri.core.renderer.SimpleRenderer;
import com.esri.core.renderer.UniqueValueRenderer;
import com.esri.core.symbol.PictureMarkerSymbol;
import com.esri.core.symbol.SimpleFillSymbol;
import com.esri.core.symbol.SimpleLineSymbol;
import com.esri.core.symbol.SimpleMarkerSymbol;
import com.esri.core.symbol.Symbol;
import com.esri.core.tasks.SpatialRelationship;
import com.esri.core.tasks.ags.query.Query;
import com.github.mikephil.charting.utils.Utils;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

/* loaded from: classes.dex */
public class ArcGISFeatureLayer extends GraphicsLayer implements PopupLayer, TimeAwareLayer {
    static MimeTypeMap M = MimeTypeMap.getSingleton();
    private static final String a = "10.0";
    boolean A;
    boolean B;
    boolean C;
    final boolean D;
    int E;
    Timer F;
    volatile String G;
    ArrayList<Integer> H;
    ArrayList<Integer> I;
    ArrayList<Integer> J;
    EditFieldsInfo K;
    OwnershipBasedAccessControlForFeatures L;
    final AtomicInteger N;
    a O;
    double P;
    private LayerServiceInfo Q;
    private TimeExtent b;
    private boolean c;
    volatile FeatureSet d;
    final transient ConcurrentLinkedQueue<WeakReference<Future<FeatureSet>>> e;
    LayerServiceInfo f;
    Envelope g;
    Envelope s;
    boolean t;
    boolean u;
    double v;
    final Options w;
    String x;
    String y;
    volatile boolean z;

    /* loaded from: classes.dex */
    public enum MODE {
        SNAPSHOT,
        ONDEMAND,
        SELECTION
    }

    /* loaded from: classes.dex */
    public static class Options {
        public MODE mode = MODE.SNAPSHOT;
        public double maxAllowableOffset = Utils.DOUBLE_EPSILON;
        public String[] outFields = null;
    }

    /* loaded from: classes.dex */
    public enum SELECTION_METHOD {
        ADD,
        NEW,
        SUBTRACT
    }

    native int nativeAddSelectedGraphic(long j, byte[] bArr, String str);

    native String nativeGetSelectionSymbol(long j);

    native int[] nativeQueryFeaturesGID(long j, int[] iArr, byte[] bArr, String str);

    native int[] nativeQueryOIDs(long j, int[] iArr, byte[] bArr, String str);

    native void nativeSetSelectionSymbol(long j, String str);

    /* loaded from: classes.dex */
    public static class EditCapabilities {
        boolean a = true;
        boolean b = true;
        boolean c = true;

        public boolean isCreate() {
            return this.a;
        }

        public boolean isUpdate() {
            return this.b;
        }

        public boolean isDelete() {
            return this.c;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class a implements Serializable {
        private static final long serialVersionUID = 1;
        boolean a = true;
        AtomicBoolean b;

        a() {
            this.b = new AtomicBoolean(ArcGISFeatureLayer.this.D);
        }

        public boolean a() {
            if (this.a) {
                if (ArcGISFeatureLayer.this.D) {
                    this.a = false;
                } else {
                    a(true);
                }
            }
            return false;
        }

        public void a(boolean z) {
            if (ArcGISFeatureLayer.this.D) {
                return;
            }
            this.b.getAndSet(false);
            if (ArcGISFeatureLayer.this.i()) {
                ArcGISFeatureLayer.this.c();
                this.a = false;
                Query query = new Query();
                query.setWhere("1=1");
                ArcGISFeatureLayer arcGISFeatureLayer = ArcGISFeatureLayer.this;
                arcGISFeatureLayer.a(arcGISFeatureLayer.a(query), new b(null, null, false, this.b, false, false), true);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class c extends a {
        private static final long serialVersionUID = 1;
        private Envelope e;

        c() {
            super();
            this.e = null;
        }

        @Override // com.esri.android.map.ags.ArcGISFeatureLayer.a
        public boolean a() {
            Envelope envelope;
            Envelope h = ArcGISFeatureLayer.this.h();
            if (ArcGISFeatureLayer.this.D) {
                this.a = false;
            } else if (this.a || (envelope = this.e) == null || !a(envelope, h) || b(h)) {
                a(true);
                return false;
            }
            return true;
        }

        @Override // com.esri.android.map.ags.ArcGISFeatureLayer.a
        public void a(boolean z) {
            if (ArcGISFeatureLayer.this.D) {
                return;
            }
            Envelope h = ArcGISFeatureLayer.this.h();
            this.b.getAndSet(false);
            ArcGISFeatureLayer.this.c();
            if (!ArcGISFeatureLayer.this.i() || h == null || h.isEmpty()) {
                return;
            }
            this.e = a(h);
            this.a = false;
            ArcGISFeatureLayer.this.s = this.e;
            a(this.e, ArcGISFeatureLayer.this.getSpatialReference());
        }

        private void a(Envelope envelope, SpatialReference spatialReference) {
            if (envelope == null || envelope.isEmpty()) {
                return;
            }
            Query query = new Query();
            query.setGeometry(envelope);
            query.setInSpatialReference(spatialReference);
            ArcGISFeatureLayer arcGISFeatureLayer = ArcGISFeatureLayer.this;
            arcGISFeatureLayer.a(arcGISFeatureLayer.a(query), new b(null, envelope, false, this.b, false, false), true);
        }

        private Envelope a(Envelope envelope) {
            if (envelope == null || envelope.isEmpty() || ArcGISFeatureLayer.this.P <= 1.0d) {
                return envelope;
            }
            Envelope envelope2 = new Envelope(envelope.getCenter(), envelope.getWidth() * ArcGISFeatureLayer.this.P, envelope.getHeight() * ArcGISFeatureLayer.this.P);
            envelope2.normalize();
            return envelope2;
        }

        /* JADX WARN: Code restructure failed: missing block: B:24:0x0059, code lost:
            if (r9.d.t != false) goto L78;
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct code enable 'Show inconsistent code' option in preferences
        */
        private boolean a(com.esri.core.geometry.Envelope r10, com.esri.core.geometry.Envelope r11) {
            /*
                Method dump skipped, instructions count: 365
                To view this dump change 'Code comments level' option to 'DEBUG'
            */
            throw new UnsupportedOperationException("Method not decompiled: com.esri.android.map.ags.ArcGISFeatureLayer.c.a(com.esri.core.geometry.Envelope, com.esri.core.geometry.Envelope):boolean");
        }

        private boolean b(Envelope envelope) {
            return (ArcGISFeatureLayer.this.s == null || ArcGISFeatureLayer.this.s.isEmpty() || envelope == null || envelope.isEmpty() || (envelope.getWidth() >= ArcGISFeatureLayer.this.s.getWidth() * ArcGISFeatureLayer.this.v && envelope.getHeight() >= ArcGISFeatureLayer.this.s.getHeight() * ArcGISFeatureLayer.this.v)) ? false : true;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class d extends a {
        private static final long serialVersionUID = 1;

        @Override // com.esri.android.map.ags.ArcGISFeatureLayer.a
        public void a(boolean z) {
        }

        @Override // com.esri.android.map.ags.ArcGISFeatureLayer.a
        public boolean a() {
            return true;
        }

        public d() {
            super();
            this.a = false;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes.dex */
    public class b implements CallbackListener<FeatureSet> {
        boolean a;
        final CallbackListener<FeatureSet> b;
        final Envelope c;
        final SELECTION_METHOD d;
        final AtomicBoolean e;
        final boolean f;
        final boolean g;
        final boolean h;

        b(CallbackListener<FeatureSet> callbackListener, Envelope envelope, boolean z, AtomicBoolean atomicBoolean, boolean z2, boolean z3) {
            this.a = true;
            this.b = callbackListener;
            this.c = envelope;
            this.d = null;
            this.e = atomicBoolean;
            this.f = z;
            this.g = z2;
            this.h = z3;
        }

        b(CallbackListener<FeatureSet> callbackListener, SELECTION_METHOD selection_method, AtomicBoolean atomicBoolean, boolean z, boolean z2) {
            this.a = true;
            this.b = callbackListener;
            this.c = null;
            this.d = selection_method;
            this.e = atomicBoolean;
            this.f = false;
            this.g = z;
            this.h = z2;
        }

        @Override // com.esri.core.map.CallbackListener
        public void onError(Throwable th) {
            Log.e(com.esri.core.internal.a.a, "ArcGISFeatureLayer.FeatureSetCallback.onError", th);
            CallbackListener<FeatureSet> callbackListener = this.b;
            if (callbackListener != null) {
                callbackListener.onError(th);
            } else {
                Log.e(com.esri.core.internal.a.a, "FeatureSetCallback.onError", th);
            }
        }

        @Override // com.esri.core.map.CallbackListener
        /* renamed from: a */
        public void onCallback(FeatureSet featureSet) {
            if (!Thread.currentThread().isInterrupted()) {
                try {
                    ArcGISFeatureLayer.this.t = featureSet.isExceededTransferLimit();
                    if (!this.h) {
                        SELECTION_METHOD selection_method = this.d;
                        if (selection_method != null) {
                            ArcGISFeatureLayer.this.a(featureSet, selection_method);
                        } else {
                            Graphic[] graphicArr = null;
                            if (this.g) {
                                ArcGISFeatureLayer arcGISFeatureLayer = ArcGISFeatureLayer.this;
                                if (featureSet != null) {
                                    graphicArr = featureSet.getGraphics();
                                }
                                arcGISFeatureLayer.b(graphicArr);
                            } else if (this.f) {
                                ArcGISFeatureLayer arcGISFeatureLayer2 = ArcGISFeatureLayer.this;
                                if (featureSet != null) {
                                    graphicArr = featureSet.getGraphics();
                                }
                                arcGISFeatureLayer2.a(graphicArr);
                            } else {
                                ArcGISFeatureLayer.this.a(featureSet);
                            }
                        }
                    }
                    AtomicBoolean atomicBoolean = this.e;
                    if (atomicBoolean != null) {
                        atomicBoolean.getAndSet(true);
                    }
                } catch (Exception e) {
                    onError(e);
                }
            }
            CallbackListener<FeatureSet> callbackListener = this.b;
            if (callbackListener != null) {
                callbackListener.onCallback(featureSet);
            }
        }
    }

    public ArcGISFeatureLayer(String str, Options options) {
        super(false);
        this.d = null;
        this.e = new ConcurrentLinkedQueue<>();
        this.f = null;
        this.g = null;
        this.s = null;
        this.t = false;
        this.u = false;
        this.v = 0.1d;
        Options options2 = new Options();
        this.w = options2;
        this.x = null;
        this.y = null;
        this.z = false;
        this.A = false;
        this.B = false;
        this.C = true;
        this.E = 0;
        this.G = "";
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new ArrayList<>();
        this.K = null;
        this.L = null;
        this.c = false;
        this.N = new AtomicInteger(0);
        this.O = null;
        this.P = 3.0d;
        this.Q = null;
        this.D = false;
        setUrl(str);
        this.renderingMode = GraphicsLayer.RenderingMode.STATIC;
        if (options != null) {
            options2.maxAllowableOffset = options.maxAllowableOffset;
            options2.mode = options.mode;
            a(options.outFields);
        }
        d(true);
    }

    public ArcGISFeatureLayer(String str, Options options, UserCredentials userCredentials) {
        this(str, options, userCredentials, false);
    }

    public ArcGISFeatureLayer(String str, Options options, UserCredentials userCredentials, boolean z) {
        this(str, options, userCredentials, z, GraphicsLayer.RenderingMode.STATIC);
    }

    public ArcGISFeatureLayer(String str, Options options, UserCredentials userCredentials, boolean z, GraphicsLayer.RenderingMode renderingMode) {
        super(false);
        this.d = null;
        this.e = new ConcurrentLinkedQueue<>();
        this.f = null;
        this.g = null;
        this.s = null;
        this.t = false;
        this.u = false;
        this.v = 0.1d;
        Options options2 = new Options();
        this.w = options2;
        this.x = null;
        this.y = null;
        this.z = false;
        this.A = false;
        this.B = false;
        this.C = true;
        this.E = 0;
        this.G = "";
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new ArrayList<>();
        this.K = null;
        this.L = null;
        this.c = false;
        this.N = new AtomicInteger(0);
        this.O = null;
        this.P = 3.0d;
        this.Q = null;
        this.c = z;
        this.D = false;
        this.renderingMode = renderingMode;
        setUrl(str);
        if (options != null) {
            options2.maxAllowableOffset = options.maxAllowableOffset;
            options2.mode = options.mode;
            a(options.outFields);
        }
        setCredentials(userCredentials);
        d(true);
    }

    public ArcGISFeatureLayer(String str, MODE mode) {
        this(str, (String) null, mode, true);
    }

    public ArcGISFeatureLayer(String str, String str2, MODE mode) {
        this(str, str2, mode, true);
    }

    public ArcGISFeatureLayer(String str, String str2, MODE mode, boolean z) {
        this(str, str2, mode, z, null, false);
    }

    public ArcGISFeatureLayer(String str, String str2, MODE mode, boolean z, UserCredentials userCredentials) {
        this(str, str2, mode, z, userCredentials, false);
    }

    public ArcGISFeatureLayer(String str, String str2, MODE mode, boolean z, UserCredentials userCredentials, boolean z2) {
        this(str, str2, mode, z, userCredentials, z2, GraphicsLayer.RenderingMode.STATIC);
    }

    public ArcGISFeatureLayer(String str, String str2, MODE mode, boolean z, UserCredentials userCredentials, boolean z2, GraphicsLayer.RenderingMode renderingMode) {
        super(false);
        this.d = null;
        this.e = new ConcurrentLinkedQueue<>();
        this.f = null;
        this.g = null;
        this.s = null;
        this.t = false;
        this.u = false;
        this.v = 0.1d;
        Options options = new Options();
        this.w = options;
        this.x = null;
        this.y = null;
        this.z = false;
        this.A = false;
        this.B = false;
        this.C = true;
        this.E = 0;
        this.G = "";
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new ArrayList<>();
        this.K = null;
        this.L = null;
        this.c = false;
        this.N = new AtomicInteger(0);
        this.O = null;
        this.P = 3.0d;
        this.Q = null;
        this.D = false;
        this.c = z2;
        setUrl(str);
        options.mode = mode;
        this.renderingMode = renderingMode;
        this.credentials = userCredentials;
        if (str2 != null) {
            try {
                this.Q = LayerServiceInfo.fromJson(com.esri.core.internal.util.d.c(str2));
            } catch (Exception e) {
                this.N.set(-1);
                Log.e(com.esri.core.internal.a.a, "Failed to initialize the ArcGISFeatureLayer.", e);
                if (e instanceof EsriSecurityException) {
                    changeStatus(OnStatusChangedListener.STATUS.fromInt(((EsriSecurityException) e).getCode()));
                    return;
                } else {
                    changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_ARCGIS_FEATURE_LAYER));
                    return;
                }
            }
        }
        d(z);
    }

    public ArcGISFeatureLayer(String str, MODE mode, UserCredentials userCredentials) {
        super(false);
        this.d = null;
        this.e = new ConcurrentLinkedQueue<>();
        this.f = null;
        this.g = null;
        this.s = null;
        this.t = false;
        this.u = false;
        this.v = 0.1d;
        Options options = new Options();
        this.w = options;
        this.x = null;
        this.y = null;
        this.z = false;
        this.A = false;
        this.B = false;
        this.C = true;
        this.E = 0;
        this.G = "";
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new ArrayList<>();
        this.K = null;
        this.L = null;
        this.c = false;
        this.N = new AtomicInteger(0);
        this.O = null;
        this.P = 3.0d;
        this.Q = null;
        this.D = false;
        setUrl(str);
        options.mode = mode;
        this.renderingMode = GraphicsLayer.RenderingMode.STATIC;
        setCredentials(userCredentials);
        d(true);
    }

    public ArcGISFeatureLayer(String str, FeatureSet featureSet, Options options) {
        this(str, (String) null, featureSet, options, true);
    }

    public ArcGISFeatureLayer(String str, String str2, FeatureSet featureSet, Options options, boolean z) {
        super(false);
        this.d = null;
        this.e = new ConcurrentLinkedQueue<>();
        this.f = null;
        this.g = null;
        this.s = null;
        this.t = false;
        this.u = false;
        this.v = 0.1d;
        Options options2 = new Options();
        this.w = options2;
        this.x = null;
        this.y = null;
        this.z = false;
        this.A = false;
        this.B = false;
        this.C = true;
        this.E = 0;
        this.G = "";
        this.H = new ArrayList<>();
        this.I = new ArrayList<>();
        this.J = new ArrayList<>();
        this.K = null;
        this.L = null;
        this.c = false;
        this.N = new AtomicInteger(0);
        this.O = null;
        this.P = 3.0d;
        this.Q = null;
        this.D = true;
        this.renderingMode = GraphicsLayer.RenderingMode.STATIC;
        this.d = featureSet;
        if (options != null) {
            options2.maxAllowableOffset = options.maxAllowableOffset;
            options2.mode = options.mode;
            a(options.outFields);
        }
        if (str != null) {
            try {
                this.f = LayerServiceInfo.fromJson(com.esri.core.internal.util.d.c(str));
            } catch (Exception e) {
                this.N.set(-1);
                Log.e(com.esri.core.internal.a.a, "Failed to initialize the ArcGISFeatureLayer.", e);
                if (e instanceof EsriSecurityException) {
                    changeStatus(OnStatusChangedListener.STATUS.fromInt(((EsriSecurityException) e).getCode()));
                    return;
                } else {
                    changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_ARCGIS_FEATURE_LAYER));
                    return;
                }
            }
        }
        if (str2 != null) {
            this.f = LayerServiceInfo.fromJson(com.esri.core.internal.util.d.c(str2), this.f);
        }
        d(z);
    }

    private void d(boolean z) {
        if (this.nativeHandle == 0) {
            this.nativeHandle = create();
        }
        if (this.nativeHandle == 0) {
            changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_ARCGIS_FEATURE_LAYER));
        } else if (z) {
            try {
                getServiceExecutor().submit(new Runnable() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.1
                    @Override // java.lang.Runnable
                    public void run() {
                        ArcGISFeatureLayer.this.initLayer();
                    }
                });
            } catch (RejectedExecutionException unused) {
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.android.map.GraphicsLayer, com.esri.android.map.Layer
    public void initLayer() {
        Graphic[] graphics;
        SpatialReference spatialReference;
        this.N.compareAndSet(-1, 0);
        k();
        try {
            if (this.c) {
                w wVar = new w();
                wVar.a(true);
                this.f = this.D ? this.f : (LayerServiceInfo) loadServiceInfo(new v(wVar, getUrl(), this.credentials));
            } else {
                this.f = this.D ? this.f : (LayerServiceInfo) loadServiceInfo(new v(getUrl(), this.credentials));
            }
            if (this.f == null) {
                throw new Exception("Failed to retrieve layer info.");
            }
            LayerServiceInfo layerServiceInfo = this.Q;
            if (layerServiceInfo != null) {
                if (layerServiceInfo.getDefinitionExpression() != null) {
                    setDefinitionExpression(this.Q.getDefinitionExpression());
                }
                if (this.Q.getDrawingInfo() != null) {
                    if (this.f.getDrawingInfo() == null) {
                        this.f.setDrawingInfo(this.Q.getDrawingInfo());
                    } else {
                        this.f.getDrawingInfo().setRenderer(this.Q.getDrawingInfo().getRenderer());
                    }
                }
                if (this.Q.getMinScale() > Utils.DOUBLE_EPSILON) {
                    this.f.setMinScale(this.Q.getMinScale());
                }
                if (this.Q.getMaxScale() > Utils.DOUBLE_EPSILON) {
                    this.f.setMaxScale(this.Q.getMaxScale());
                }
                this.Q = null;
            }
            if (this.f.getDrawingInfo() != null) {
                a(this.f.getDrawingInfo().getRenderer(), this.f.getFields());
            }
            if (getName() == null || getName().length() < 1) {
                setName(this.f.getName());
            }
            initializeMinMaxScale(this.f.getMinScale(), this.f.getMaxScale());
            LayerServiceInfo layerServiceInfo2 = this.f;
            this.G = layerServiceInfo2 == null ? "" : layerServiceInfo2.getObjectIdField();
            if (this.w.outFields != null && this.G != null && this.G.length() > 0) {
                a(this.w.outFields);
            }
            MapGeometry extent = this.f.getExtent();
            if (this.f.getExtent() == null && this.d != null && (graphics = this.d.getGraphics()) != null && graphics.length > 0 && (spatialReference = GraphicsUtil.getSpatialReference(graphics[0])) != null) {
                extent = new MapGeometry(new Envelope(), spatialReference);
                this.f.setExtent(extent);
            }
            if (extent != null) {
                setFullExtent((Envelope) extent.getGeometry());
                setDefaultSpatialReference(extent.getSpatialReference());
            }
            this.y = this.f.getDefinitionExpression();
            DrawingInfo drawingInfo = this.f.getDrawingInfo();
            if (drawingInfo != null && getRenderer() == null) {
                setRenderer(drawingInfo.getRenderer());
            }
            l();
            Geometry.Type geometryType = this.f.getGeometryType();
            this.C = this.f.isAllowGeometryUpdates();
            if (this.f.getType() != null) {
                this.A = "table".equalsIgnoreCase(this.f.getType());
            }
            this.K = this.f.getEditFieldsInfo();
            this.L = this.f.getOwnershipBasedAccessControlForFeatures();
            if (this.serviceInfo != null && (this.serviceInfo instanceof String)) {
                this.f.setCapabilities((String) this.serviceInfo);
            }
            if (this.f.getCapabilities() != null) {
                boolean isEditingSupported = this.f.getCapabilities().isEditingSupported();
                this.B = isEditingSupported;
                if (isEditingSupported && this.D) {
                    this.B = false;
                }
            }
            if (getRenderer() == null) {
                if (Geometry.Type.POLYGON == geometryType) {
                    SimpleFillSymbol simpleFillSymbol = new SimpleFillSymbol(1677721600);
                    simpleFillSymbol.setOutline(new SimpleLineSymbol(-16777216, 2.0f));
                    setRenderer(new SimpleRenderer(simpleFillSymbol));
                } else if (Geometry.Type.POLYLINE == geometryType) {
                    setRenderer(new SimpleRenderer(new SimpleLineSymbol(SupportMenu.CATEGORY_MASK, 1.0f)));
                } else if (Geometry.Type.POINT == geometryType) {
                    setRenderer(new SimpleRenderer(new SimpleMarkerSymbol(-16776961, 5, SimpleMarkerSymbol.STYLE.SQUARE)));
                }
            }
            if (this.D && this.d != null) {
                if (this.d.getSpatialReference() != null && getSpatialReference() != null && com.esri.core.internal.util.d.a(this.d.getSpatialReference(), getSpatialReference())) {
                    throw new UnsupportedOperationException("The Feature collection need to be projected.");
                }
                a(this.d);
                updateGraphicsVisibility();
                this.d = null;
            }
            int i = AnonymousClass3.a[this.w.mode.ordinal()];
            if (i == 1) {
                this.O = new a();
            } else if (i == 2) {
                this.O = new c();
            } else if (i == 3) {
                this.O = new d();
            }
            super.initLayer();
            j();
        } catch (InterruptedException unused) {
            Log.i(com.esri.core.internal.a.a, "The operation is cancelled.");
        } catch (Exception e) {
            this.N.set(-1);
            Log.e(com.esri.core.internal.a.a, "Failed to initialize the ArcGISFeatureLayer.", e);
            if (e instanceof EsriSecurityException) {
                changeStatus(OnStatusChangedListener.STATUS.fromInt(((EsriSecurityException) e).getCode()));
            } else {
                changeStatus(OnStatusChangedListener.STATUS.fromInt(OnStatusChangedListener.EsriStatusException.INIT_FAILED_ARCGIS_FEATURE_LAYER));
            }
        }
    }

    private void k() {
        if (this.d != null) {
            for (Graphic graphic : this.d.getGraphics()) {
                Symbol symbol = graphic.getSymbol();
                if (symbol instanceof PictureMarkerSymbol) {
                    PictureMarkerSymbol pictureMarkerSymbol = (PictureMarkerSymbol) symbol;
                    if (pictureMarkerSymbol.getDrawable() == null && pictureMarkerSymbol.getUrl() != null) {
                        try {
                            pictureMarkerSymbol.fetchDrawable();
                        } catch (IOException unused) {
                        }
                    }
                }
            }
        }
    }

    public LayerServiceInfo getLayerServiceInfo() {
        return this.f;
    }

    @Override // com.esri.android.map.popup.PopupLayer
    public boolean isPopupEditable(Feature feature) {
        if (getPopupInfo() == null || getCapabilities() == null || this.D) {
            return false;
        }
        LayerServiceCapabilities capabilities = getCapabilities();
        if (capabilities.isEditingSupported()) {
            if (capabilities.isUpdateSupported() || !(capabilities.isCreateSupported() || capabilities.isDeleteSupported())) {
                if (feature != null && this.f.getOwnershipBasedAccessControlForFeatures() != null) {
                    String userName = this.credentials == null ? null : this.credentials.getUserName();
                    if (!this.f.getOwnershipBasedAccessControlForFeatures().isAllowOthersToUpdate()) {
                        EditFieldsInfo editFieldsInfo = this.f.getEditFieldsInfo();
                        return a(userName, editFieldsInfo != null ? (String) feature.getAttributeValue(editFieldsInfo.getCreatorField()) : null);
                    }
                }
                return true;
            }
            return false;
        }
        return false;
    }

    private boolean a(String str, String str2) {
        return str2 != null && ((str2 != null && str2.length() == 0) || str2 == null || str2.equals(str));
    }

    @Override // com.esri.android.map.popup.PopupLayer
    public boolean isPopupDeletable(Feature feature) {
        if (getPopupInfo() == null || getCapabilities() == null || this.D) {
            return false;
        }
        LayerServiceCapabilities capabilities = this.f.getCapabilities();
        if (capabilities.isEditingSupported()) {
            if (capabilities.isDeleteSupported() || !(capabilities.isCreateSupported() || capabilities.isUpdateSupported())) {
                if (feature != null && this.f.getOwnershipBasedAccessControlForFeatures() != null) {
                    String userName = this.credentials == null ? null : this.credentials.getUserName();
                    if (!this.f.getOwnershipBasedAccessControlForFeatures().isAllowOthersToDelete()) {
                        EditFieldsInfo editFieldsInfo = this.f.getEditFieldsInfo();
                        return a(userName, editFieldsInfo != null ? (String) feature.getAttributeValue(editFieldsInfo.getCreatorField()) : null);
                    }
                }
                return true;
            }
            return false;
        }
        return false;
    }

    @Override // com.esri.android.map.popup.PopupLayer
    public boolean isPopupAllowGeometryUpdate(Feature feature) {
        return isAllowGeometryUpdates();
    }

    private void l() {
        List<FeatureTemplate> templates;
        Renderer renderer = getRenderer();
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null || renderer == null) {
            return;
        }
        if (layerServiceInfo.getTemplates() == null || this.f.getTemplates().isEmpty()) {
            if (this.f.getSubTypes() == null || this.f.getSubTypes().length <= 0) {
                if (renderer instanceof SimpleRenderer) {
                    SimpleRenderer simpleRenderer = (SimpleRenderer) renderer;
                    this.f.setTemplates(Arrays.asList(new FeatureTemplate(simpleRenderer.getLabel() == null ? "" : simpleRenderer.getLabel(), simpleRenderer.getDescription() != null ? simpleRenderer.getDescription() : "", new HashMap(), com.esri.core.internal.util.d.b(this.f.getGeometryType()))));
                } else if (renderer instanceof UniqueValueRenderer) {
                    FeatureType[] types = ((UniqueValueRenderer) renderer).toTypes(this.f.getFields(), this.f.getGeometryType());
                    if (types != null) {
                        this.f.setSubTypes(types);
                    }
                } else if (!(renderer instanceof ClassBreaksRenderer) || (templates = ((ClassBreaksRenderer) renderer).toTemplates(this.f.getGeometryType())) == null) {
                } else {
                    this.f.setTemplates(templates);
                }
            }
        }
    }

    public String getDefinitionExpression() {
        return this.x;
    }

    public void setDefinitionExpression(String str) {
        String str2 = this.x;
        if (str2 != str) {
            this.x = str;
            if (!isInitialized() || this.O.a) {
                return;
            }
            if ((str == null || str.equals(str2)) && (str != null || str2 == null)) {
                return;
            }
            this.O.a = true;
            e();
        }
    }

    public String getDefaultDefinitionExpression() {
        return this.y;
    }

    public Symbol getSelectionSymbol() {
        String nativeGetSelectionSymbol;
        if (this.nativeHandle == 0 || (nativeGetSelectionSymbol = nativeGetSelectionSymbol(this.nativeHandle)) == null) {
            return null;
        }
        try {
            return com.esri.core.internal.util.d.h(com.esri.core.internal.util.d.c(nativeGetSelectionSymbol));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void setSelectionSymbol(Symbol symbol) {
        if (this.nativeHandle != 0) {
            try {
                nativeSetSelectionSymbol(this.nativeHandle, symbol == null ? null : symbol.toJson());
            } catch (Exception e) {
                throw new IllegalArgumentException(e);
            }
        }
    }

    public double getBufferFactor() {
        return this.P;
    }

    public void setBufferFactor(double d2) {
        this.P = d2;
    }

    public MODE getMode() {
        return this.w.mode;
    }

    public Field[] getFields() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo != null) {
            return layerServiceInfo.getFields();
        }
        return null;
    }

    public Field getField(String str) {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo != null) {
            return layerServiceInfo.getField(str);
        }
        return null;
    }

    public boolean isAutoRefreshOnExpiration() {
        return this.z;
    }

    public void setAutoRefreshOnExpiration(boolean z) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        this.z = z;
    }

    public int getExpirationInterval() {
        return this.E;
    }

    public void setExpirationInterval(int i) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        this.E = i;
        Timer timer = this.F;
        if (timer != null) {
            timer.cancel();
        }
        if (this.E > 0) {
            Timer timer2 = new Timer(false);
            this.F = timer2;
            TimerTask timerTask = new TimerTask() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.4
                @Override // java.util.TimerTask, java.lang.Runnable
                public void run() {
                    Log.i(com.esri.core.internal.a.a, "Features expired.");
                    ArcGISFeatureLayer arcGISFeatureLayer = ArcGISFeatureLayer.this;
                    arcGISFeatureLayer.c(arcGISFeatureLayer.isAutoRefreshOnExpiration());
                }
            };
            int i2 = this.E;
            timer2.scheduleAtFixedRate(timerTask, i2 * 1000, i2 * 1000);
        }
    }

    void a(FeatureSet featureSet) {
        Map<Integer, Integer> g = g();
        if (featureSet != null && featureSet.getGraphics() != null && featureSet.getGraphics().length > 0) {
            Map<Integer, Graphic> graphicMap = FeatureUtil.getGraphicMap(featureSet, featureSet.getObjectIdFieldName() == null ? this.G : featureSet.getObjectIdFieldName());
            ArrayList arrayList = new ArrayList();
            ArrayList arrayList2 = new ArrayList();
            ArrayList arrayList3 = new ArrayList();
            for (Integer num : g.keySet()) {
                if (graphicMap.containsKey(num)) {
                    arrayList.add(g.get(num));
                    arrayList2.add(graphicMap.remove(num));
                } else if (num.intValue() >= 0 && !this.H.contains(num) && !this.I.contains(num)) {
                    arrayList3.add(g.get(num));
                }
            }
            if (!arrayList.isEmpty()) {
                updateGraphics(com.esri.core.internal.util.a.a(arrayList), (Graphic[]) arrayList2.toArray(new Graphic[arrayList2.size()]));
            }
            if (!arrayList3.isEmpty()) {
                removeGraphics(com.esri.core.internal.util.a.a(arrayList3));
            }
            if (!graphicMap.isEmpty()) {
                addGraphics((Graphic[]) graphicMap.values().toArray(new Graphic[graphicMap.size()]));
            }
            Iterator<Integer> it = this.J.iterator();
            while (it.hasNext()) {
                Integer num2 = g.get(it.next());
                if (num2 != null) {
                    setGraphicVisible(num2.intValue(), false);
                }
            }
            return;
        }
        ArrayList arrayList4 = new ArrayList();
        for (Integer num3 : g.keySet()) {
            if (num3.intValue() >= 0 && !this.H.contains(num3) && !this.I.contains(num3)) {
                arrayList4.add(g.get(num3));
            }
        }
        if (arrayList4.isEmpty()) {
            return;
        }
        removeGraphics(com.esri.core.internal.util.a.a(arrayList4));
    }

    void a(Graphic[] graphicArr) {
        if (graphicArr == null || graphicArr.length == 0) {
            return;
        }
        int[] selectionIDs = getSelectionIDs();
        if (getNumberOfGraphics() < 1 && getObjectIdField() != null) {
            Map<Integer, Integer> g = g();
            ArrayList arrayList = new ArrayList();
            for (Graphic graphic : graphicArr) {
                Integer num = (Integer) graphic.getAttributeValue(this.G);
                if (num != null && (selectionIDs == null || Arrays.binarySearch(selectionIDs, num.intValue()) < 0)) {
                    Integer num2 = g.get(num);
                    if (num2 != null) {
                        removeGraphic(num2.intValue());
                    }
                    arrayList.add(graphic);
                }
            }
            graphicArr = (Graphic[]) arrayList.toArray(new Graphic[0]);
        }
        addGraphics(graphicArr);
    }

    void b(Graphic[] graphicArr) {
        Integer num;
        if (graphicArr == null || graphicArr.length == 0) {
            return;
        }
        int[] selectionIDs = getSelectionIDs();
        if (getNumberOfGraphics() <= 0 || getObjectIdField() == null) {
            return;
        }
        Map<Integer, Integer> g = g();
        ArrayList arrayList = new ArrayList();
        for (Graphic graphic : graphicArr) {
            Integer num2 = (Integer) graphic.getAttributeValue(this.G);
            if (num2 != null && ((selectionIDs == null || Arrays.binarySearch(selectionIDs, num2.intValue()) < 0) && (num = g.get(num2)) != null)) {
                removeGraphic(num.intValue());
                arrayList.add(graphic);
            }
        }
        addGraphics((Graphic[]) arrayList.toArray(new Graphic[0]));
    }

    void a(FeatureSet featureSet, SELECTION_METHOD selection_method) {
        if (selection_method == null || selection_method == SELECTION_METHOD.NEW) {
            clearSelection();
        }
        Graphic[] graphics = featureSet == null ? null : featureSet.getGraphics();
        if (graphics != null) {
            Map<Integer, Integer> g = g();
            for (Graphic graphic : graphics) {
                Map<String, Object> attributes = graphic.getAttributes();
                Integer num = g.get(attributes == null ? null : (Integer) attributes.get(this.G));
                int i = AnonymousClass3.b[selection_method.ordinal()];
                if (i == 1 || i == 2) {
                    if (num != null) {
                        removeGraphic(num.intValue());
                    }
                    setSelectedGraphics(new int[]{addGraphic(graphic)}, true);
                } else if (i == 3) {
                    if (this.w.mode == MODE.SELECTION) {
                        if (num != null) {
                            removeGraphic(num.intValue());
                        }
                    } else if (num != null) {
                        setSelectedGraphics(new int[]{num.intValue()}, false);
                    }
                }
            }
        }
    }

    void c() {
        Iterator<WeakReference<Future<FeatureSet>>> it = this.e.iterator();
        while (it.hasNext()) {
            WeakReference<Future<FeatureSet>> next = it.next();
            if (next != null) {
                this.e.remove(next);
                Future<FeatureSet> future = next.get();
                if (future != null) {
                    future.cancel(true);
                }
            }
        }
    }

    Envelope d() {
        if (this.g == null) {
            Envelope fullExtent = getFullExtent();
            if (fullExtent == null || fullExtent.isEmpty()) {
                return null;
            }
            SpatialReference defaultSpatialReference = getDefaultSpatialReference();
            SpatialReference spatialReference = getSpatialReference();
            if (spatialReference != null && defaultSpatialReference != null && !com.esri.core.internal.util.d.a(defaultSpatialReference, spatialReference)) {
                this.g = new Envelope();
                this.g = (Envelope) GeometryEngine.project(fullExtent, defaultSpatialReference, spatialReference);
            } else {
                this.g = fullExtent;
            }
        }
        return this.g;
    }

    void e() {
        a aVar;
        if (isVisible() && this.N.get() == 2 && (aVar = this.O) != null) {
            aVar.a();
        }
    }

    public void refresh() {
        e();
    }

    void c(boolean z) {
        if (isInitialized()) {
            this.O.a = true;
            this.O.a(z);
            Log.i(com.esri.core.internal.a.a, "Refresh Features:" + z);
        }
    }

    void a(Query query, final CallbackListener<FeatureSet> callbackListener, boolean z) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        final String url = getUrl();
        h hVar = new h(c(query), url, this.credentials, new TaskListener<FeatureSet>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.5
            @Override // com.esri.core.internal.tasks.TaskListener
            public void onError(Throwable th) {
                callbackListener.onError(th);
                Log.w(com.esri.core.internal.a.a, th);
            }

            @Override // com.esri.core.internal.tasks.TaskListener
            /* renamed from: a */
            public void onCompletion(short s, FeatureSet featureSet) {
                if (s == 1) {
                    ArcGISFeatureLayer.this.b(featureSet);
                    callbackListener.onCallback(featureSet);
                }
            }
        });
        if (z) {
            this.e.add(new WeakReference<>(getPoolExecutor().submit(hVar)));
            return;
        }
        try {
            getServiceExecutor().submit(hVar);
        } catch (RejectedExecutionException unused) {
        }
    }

    void a(Query query, final CallbackListener<int[]> callbackListener) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        query.setReturnIdsOnly(true);
        final String url = getUrl();
        try {
            getServiceExecutor().submit(new h(c(query), url, this.credentials, new TaskListener<FeatureSet>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.6
                @Override // com.esri.core.internal.tasks.TaskListener
                public void onError(Throwable th) {
                    callbackListener.onError(th);
                    Log.w(com.esri.core.internal.a.a, th);
                }

                @Override // com.esri.core.internal.tasks.TaskListener
                /* renamed from: a */
                public void onCompletion(short s, FeatureSet featureSet) {
                    if (s == 1) {
                        ArcGISFeatureLayer.this.b(featureSet);
                        ArcGISFeatureLayer.this.a(callbackListener, featureSet);
                    }
                }
            }));
        } catch (RejectedExecutionException unused) {
        }
    }

    void b(FeatureSet featureSet) {
        LayerServiceInfo layerServiceInfo;
        if (featureSet == null || featureSet.getFields() != null || (layerServiceInfo = this.f) == null || layerServiceInfo.getFields() == null) {
            return;
        }
        featureSet.setFields(Arrays.asList(this.f.getFields()));
    }

    void a(CallbackListener<int[]> callbackListener, FeatureSet featureSet) {
        int[] iArr;
        Integer[] objectIds;
        if (featureSet == null || (objectIds = featureSet.getObjectIds()) == null || objectIds.length <= 0) {
            iArr = null;
        } else {
            iArr = new int[objectIds.length];
            int i = 0;
            for (Integer num : objectIds) {
                iArr[i] = num.intValue();
                i++;
            }
        }
        callbackListener.onCallback(iArr);
    }

    void b(final Query query, final CallbackListener<FeatureSet> callbackListener) {
        final long j = this.nativeHandle;
        try {
            getServiceExecutor().submit(new Runnable() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.7
                @Override // java.lang.Runnable
                public void run() {
                    String[] strArr;
                    try {
                        if (ArcGISFeatureLayer.this.isInitialized()) {
                            ArrayList arrayList = new ArrayList();
                            if (ArcGISFeatureLayer.this.w.outFields != null) {
                                for (String str : ArcGISFeatureLayer.this.w.outFields) {
                                    if (str != null && str.equals("*")) {
                                        break;
                                    }
                                    arrayList.add(str);
                                }
                            }
                            FeatureSet featureSet = null;
                            int[] nativeQueryFeaturesGID = ArcGISFeatureLayer.this.nativeQueryFeaturesGID(j, query.getObjectIds(), query.getGeometry() == null ? null : GeometryEngine.geometryToEsriShape(query.getGeometry()), ArcGISFeatureLayer.this.getObjectIdField());
                            if (nativeQueryFeaturesGID != null && nativeQueryFeaturesGID.length > 0) {
                                ArrayList arrayList2 = new ArrayList();
                                for (int i : nativeQueryFeaturesGID) {
                                    Graphic graphic = ArcGISFeatureLayer.this.getGraphic(i);
                                    if (graphic != null) {
                                        arrayList2.add(graphic);
                                    }
                                }
                                if (!arrayList2.isEmpty()) {
                                    featureSet = new FeatureSet();
                                    featureSet.setSpatialReference(ArcGISFeatureLayer.this.getSpatialReference());
                                    featureSet.setGraphics((Graphic[]) arrayList2.toArray(new Graphic[0]));
                                }
                            }
                            callbackListener.onCallback(featureSet);
                            return;
                        }
                        callbackListener.onError(new UnsupportedOperationException("Layer is not initialized."));
                    } catch (Exception e) {
                        Log.e(com.esri.core.internal.a.a, "query Cached Features Failed.", e);
                        callbackListener.onError(e);
                    }
                }
            });
        } catch (RejectedExecutionException unused) {
        }
    }

    void c(final Query query, final CallbackListener<int[]> callbackListener) {
        query.isReturnIdsOnly();
        final long j = this.nativeHandle;
        try {
            getServiceExecutor().submit(new Runnable() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.8
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        if (ArcGISFeatureLayer.this.isInitialized()) {
                            if (ArcGISFeatureLayer.this.G != null && ArcGISFeatureLayer.this.G.length() > 0) {
                                new ArrayList().add(ArcGISFeatureLayer.this.G);
                            }
                            callbackListener.onCallback(ArcGISFeatureLayer.this.nativeQueryOIDs(j, query.getObjectIds(), query.getGeometry() == null ? null : GeometryEngine.geometryToEsriShape(query.getGeometry()), ArcGISFeatureLayer.this.getObjectIdField()));
                            return;
                        }
                        callbackListener.onError(new UnsupportedOperationException("Layer is not initialized."));
                    } catch (Exception e) {
                        Log.e(com.esri.core.internal.a.a, "query Cached FeaturesID Failed.", e);
                        callbackListener.onError(e);
                    }
                }
            });
        } catch (RejectedExecutionException unused) {
        }
    }

    Query a(Query query) {
        int i;
        TimeExtent timeExtent;
        StringBuilder sb = new StringBuilder();
        String str = this.x;
        if (str == null || str.trim().length() <= 0) {
            i = 0;
        } else {
            sb.append(this.x);
            i = 1;
        }
        String where = query.getWhere();
        if (where != null && where.trim().length() > 0) {
            if (i > 0) {
                sb.append(" AND ");
            }
            sb.append(where);
            i++;
        }
        if (i > 0) {
            query.setWhere(sb.toString());
        }
        if (this.w.outFields != null && this.w.outFields.length > 0) {
            query.setOutFields(this.w.outFields);
        } else if (query.getOutFields() == null) {
            query.setOutFields(new String[]{"*"});
        }
        if (getSpatialReference() != null) {
            query.setOutSpatialReference(getSpatialReference());
        }
        if (isTimeAware() && (timeExtent = this.b) != null) {
            query.setTimeExtent(timeExtent);
        }
        if (!this.B && this.w.maxAllowableOffset > Utils.DOUBLE_EPSILON) {
            query.setMaxAllowableOffset(this.w.maxAllowableOffset);
        }
        return query;
    }

    public void selectFeatures(Query query, SELECTION_METHOD selection_method, CallbackListener<FeatureSet> callbackListener) {
        Query a2 = a(query);
        if (b(a2)) {
            b(a2, new b(callbackListener, selection_method, null, true, true));
        } else {
            a(a2, new b(callbackListener, selection_method, null, true, false), false);
        }
    }

    public Graphic[] getSelectedFeatures() {
        if (getNumberOfGraphics() < 1) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        int[] selectionIDs = getSelectionIDs();
        if (selectionIDs != null) {
            for (int i : selectionIDs) {
                Graphic graphic = getGraphic(i);
                if (graphic != null) {
                    arrayList.add(graphic);
                }
            }
        }
        return (Graphic[]) arrayList.toArray(new Graphic[0]);
    }

    Map<Integer, Graphic> f() {
        int[] selectionIDs;
        Integer num;
        HashMap hashMap = new HashMap();
        if (getNumberOfGraphics() > 0 && getObjectIdField() != null && (selectionIDs = getSelectionIDs()) != null) {
            for (int i : selectionIDs) {
                Graphic graphic = getGraphic(i);
                if (graphic != null && (num = (Integer) graphic.getAttributeValue(this.G)) != null) {
                    hashMap.put(num, graphic);
                }
            }
        }
        return hashMap;
    }

    Map<Integer, Integer> g() {
        HashMap hashMap = new HashMap();
        int[] graphicIDs = getGraphicIDs();
        if (graphicIDs != null && graphicIDs.length > 0 && this.G != null && this.G.length() > 0) {
            int[] graphicOIDs = getGraphicOIDs(this.G);
            for (int i = 0; i < graphicIDs.length; i++) {
                hashMap.put(new Integer(graphicOIDs[i]), new Integer(graphicIDs[i]));
            }
        }
        return hashMap;
    }

    public int getGraphicIDWithOID(int i) {
        int[] graphicOIDs;
        int[] graphicIDs = getGraphicIDs();
        if (graphicIDs != null && graphicIDs.length > 0 && this.G != null && this.G.length() > 0 && (graphicOIDs = getGraphicOIDs(this.G)) != null && graphicOIDs.length > 0) {
            for (int i2 = 0; i2 < graphicOIDs.length; i2++) {
                if (graphicOIDs[i2] == i) {
                    return graphicIDs[i2];
                }
            }
        }
        return -1;
    }

    public Map<Integer, Integer> getGraphicIDsWithOIDs(int[] iArr) {
        int[] graphicOIDs;
        HashMap hashMap = new HashMap();
        if (iArr != null && iArr.length > 0) {
            for (int i : iArr) {
                hashMap.put(Integer.valueOf(i), -1);
            }
            int[] graphicIDs = getGraphicIDs();
            if (graphicIDs != null && graphicIDs.length > 0 && this.G != null && this.G.length() > 0 && (graphicOIDs = getGraphicOIDs(this.G)) != null && graphicOIDs.length > 0) {
                for (int i2 : iArr) {
                    int i3 = 0;
                    while (true) {
                        if (i3 >= graphicOIDs.length) {
                            break;
                        } else if (graphicOIDs[i3] == i2) {
                            hashMap.put(Integer.valueOf(i2), Integer.valueOf(graphicIDs[i3]));
                            break;
                        } else {
                            i3++;
                        }
                    }
                }
            }
        }
        return hashMap;
    }

    public void addAttachment(int i, File file, CallbackListener<FeatureEditResult> callbackListener) {
        String str;
        String name = file.getName();
        if (name != null && name.length() > 2) {
            int lastIndexOf = name.lastIndexOf(46) + 1;
            int length = name.length();
            if (lastIndexOf > 0 && lastIndexOf < length - 1) {
                str = M.getMimeTypeFromExtension(name.substring(lastIndexOf, length));
                addAttachment(i, file, str, callbackListener);
            }
        }
        str = null;
        addAttachment(i, file, str, callbackListener);
    }

    public void addAttachment(int i, File file, String str, final CallbackListener<FeatureEditResult> callbackListener) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        com.esri.core.internal.tasks.ags.c cVar = new com.esri.core.internal.tasks.ags.c();
        cVar.a(i);
        cVar.a(file, null);
        if (str != null && str.length() > 0) {
            cVar.b(str);
        }
        final String url = getUrl();
        try {
            getServiceExecutor().submit(new com.esri.core.internal.tasks.ags.a(cVar, url, this.credentials, new TaskListener<FeatureEditResult>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.9
                @Override // com.esri.core.internal.tasks.TaskListener
                public void onError(Throwable th) {
                    callbackListener.onError(th);
                    Log.w(com.esri.core.internal.a.a, th);
                }

                @Override // com.esri.core.internal.tasks.TaskListener
                /* renamed from: a */
                public void onCompletion(short s, FeatureEditResult featureEditResult) {
                    if (s == 1) {
                        callbackListener.onCallback(featureEditResult);
                    }
                }
            }));
        } catch (RejectedExecutionException unused) {
        }
    }

    public void deleteAttachments(int i, int[] iArr, final CallbackListener<FeatureEditResult[]> callbackListener) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        com.esri.core.internal.tasks.ags.c cVar = new com.esri.core.internal.tasks.ags.c();
        cVar.a(i);
        cVar.a(a(iArr));
        final String url = getUrl();
        try {
            getServiceExecutor().submit(new com.esri.core.internal.tasks.ags.b(cVar, url, this.credentials, new TaskListener<FeatureEditResult[]>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.10
                @Override // com.esri.core.internal.tasks.TaskListener
                public void onError(Throwable th) {
                    callbackListener.onError(th);
                    Log.w(com.esri.core.internal.a.a, th);
                }

                @Override // com.esri.core.internal.tasks.TaskListener
                /* renamed from: a */
                public void onCompletion(short s, FeatureEditResult[] featureEditResultArr) {
                    if (s == 1) {
                        callbackListener.onCallback(featureEditResultArr);
                    }
                }
            }));
        } catch (RejectedExecutionException unused) {
        }
    }

    private long[] a(int[] iArr) {
        if (iArr == null || iArr.length <= 0) {
            return null;
        }
        long[] jArr = new long[iArr.length];
        for (int i = 0; i < iArr.length; i++) {
            jArr[i] = iArr[i];
        }
        return jArr;
    }

    public void queryAttachmentInfos(int i, final CallbackListener<AttachmentInfo[]> callbackListener) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        com.esri.core.internal.tasks.ags.c cVar = new com.esri.core.internal.tasks.ags.c();
        cVar.a(i);
        final String url = getUrl();
        try {
            getServiceExecutor().submit(new com.esri.core.internal.tasks.ags.d(cVar, url, this.credentials, new TaskListener<AttachmentInfo[]>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.11
                @Override // com.esri.core.internal.tasks.TaskListener
                public void onError(Throwable th) {
                    callbackListener.onError(th);
                    Log.w(com.esri.core.internal.a.a, th);
                }

                @Override // com.esri.core.internal.tasks.TaskListener
                /* renamed from: a */
                public void onCompletion(short s, AttachmentInfo[] attachmentInfoArr) {
                    if (s == 1) {
                        callbackListener.onCallback(attachmentInfoArr);
                    }
                }
            }));
        } catch (RejectedExecutionException unused) {
        }
    }

    public void applyEdits(final Graphic[] graphicArr, final Graphic[] graphicArr2, final Graphic[] graphicArr3, final CallbackListener<FeatureEditResult[][]> callbackListener) {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        i iVar = new i();
        iVar.a = graphicArr;
        iVar.b = c(graphicArr2);
        iVar.c = graphicArr3;
        iVar.e = this.C;
        iVar.a(getSpatialReference());
        final String url = getUrl();
        try {
            getServiceExecutor().submit(new com.esri.core.internal.tasks.ags.h(iVar, url, this.credentials, new TaskListener<FeatureEditResult[][]>() { // from class: com.esri.android.map.ags.ArcGISFeatureLayer.2
                @Override // com.esri.core.internal.tasks.TaskListener
                public void onError(Throwable th) {
                    callbackListener.onError(th);
                    Log.w(com.esri.core.internal.a.a, th);
                }

                @Override // com.esri.core.internal.tasks.TaskListener
                /* renamed from: a */
                public void onCompletion(short s, FeatureEditResult[][] featureEditResultArr) {
                    if (s == 1) {
                        ArcGISFeatureLayer.this.a(graphicArr, graphicArr2, graphicArr3, featureEditResultArr, callbackListener);
                        callbackListener.onCallback(featureEditResultArr);
                    }
                }
            }));
        } catch (RejectedExecutionException unused) {
        }
    }

    void a(Graphic[] graphicArr, Graphic[] graphicArr2, Graphic[] graphicArr3, FeatureEditResult[][] featureEditResultArr, CallbackListener<FeatureEditResult[][]> callbackListener) {
        if (featureEditResultArr != null) {
            try {
                if (featureEditResultArr.length != 3) {
                    return;
                }
                String userName = getCredentials() == null ? null : getCredentials().getUserName();
                Long l = new Long(System.currentTimeMillis());
                if (graphicArr != null && graphicArr.length > 0) {
                    ArrayList arrayList = new ArrayList();
                    for (int i = 0; i < featureEditResultArr[0].length; i++) {
                        if (featureEditResultArr[0][i].isSuccess()) {
                            Map<String, Object> attributes = graphicArr[i].getAttributes();
                            if (this.G != null && !this.G.equals("")) {
                                attributes.put(this.G, Integer.valueOf((int) featureEditResultArr[0][i].getObjectId()));
                            }
                            if (this.f.getGlobalIdField() != null && !this.f.getGlobalIdField().equals("")) {
                                attributes.put(this.f.getGlobalIdField(), featureEditResultArr[0][i].getGlobalId());
                            }
                            EditFieldsInfo editFieldsInfo = this.K;
                            if (editFieldsInfo != null) {
                                if (editFieldsInfo.getCreatorField() != null) {
                                    attributes.put(this.K.getCreatorField(), userName);
                                }
                                if (this.K.getCreationDateField() != null) {
                                    attributes.put(this.K.getCreationDateField(), l);
                                }
                            }
                            arrayList.add(new Graphic(graphicArr[i].getGeometry(), (Symbol) null, attributes));
                        }
                    }
                    a((Graphic[]) arrayList.toArray(new Graphic[0]));
                }
                if (graphicArr2 != null && graphicArr2.length > 0) {
                    ArrayList arrayList2 = new ArrayList();
                    for (int i2 = 0; i2 < featureEditResultArr[1].length; i2++) {
                        if (featureEditResultArr[1][i2].isSuccess()) {
                            arrayList2.add(Integer.valueOf((int) featureEditResultArr[1][i2].getObjectId()));
                        }
                    }
                    a((List<Integer>) arrayList2);
                }
                if (graphicArr3 == null || graphicArr3.length <= 0) {
                    return;
                }
                ArrayList arrayList3 = new ArrayList();
                for (int i3 = 0; i3 < featureEditResultArr[2].length; i3++) {
                    if (featureEditResultArr[2][i3].isSuccess() && graphicArr3[i3] != null) {
                        Map<String, Object> attributes2 = graphicArr3[i3].getAttributes();
                        EditFieldsInfo editFieldsInfo2 = this.K;
                        if (editFieldsInfo2 != null) {
                            if (editFieldsInfo2.getEditorField() != null) {
                                attributes2.put(this.K.getEditorField(), userName);
                            }
                            if (this.K.getEditDateField() != null) {
                                attributes2.put(this.K.getEditDateField(), l);
                            }
                        }
                        arrayList3.add(new Graphic(graphicArr3[i3].getGeometry(), (Symbol) null, attributes2));
                    }
                }
                b((Graphic[]) arrayList3.toArray(new Graphic[0]));
            } catch (Exception e) {
                Log.e(com.esri.core.internal.a.a, "Failed when updating local features.", new IllegalArgumentException("The applyEdits failed.\n" + e));
                callbackListener.onError(e);
            }
        }
    }

    void a(List<Integer> list) {
        if (list.isEmpty()) {
            return;
        }
        Map<Integer, Integer> g = g();
        for (Integer num : list) {
            Integer num2 = g.get(num);
            if (num2 != null) {
                removeGraphic(num2.intValue());
            }
        }
    }

    final long[] c(Graphic[] graphicArr) {
        if (graphicArr == null || graphicArr.length <= 0) {
            return null;
        }
        long[] jArr = new long[graphicArr.length];
        for (int i = 0; i < graphicArr.length; i++) {
            jArr[i] = a(graphicArr[i], this.G);
        }
        return jArr;
    }

    private long a(Graphic graphic, String str) {
        Object attributeValue = graphic.getAttributeValue(str);
        if (attributeValue instanceof Integer) {
            return ((Integer) attributeValue).longValue();
        }
        if (attributeValue instanceof Long) {
            return ((Long) attributeValue).longValue();
        }
        return -1L;
    }

    public boolean isEditable() {
        if (this.D) {
            return false;
        }
        return this.B;
    }

    public EditInfo getEditInfo(Graphic graphic, EditInfo.ACTION_TYPE action_type) {
        String str;
        long a2;
        if (this.K == null) {
            return null;
        }
        if (AnonymousClass3.c[action_type.ordinal()] == 1) {
            str = this.K.getEditorField() != null ? (String) graphic.getAttributeValue(this.K.getEditorField()) : null;
            if (this.K.getEditDateField() != null) {
                a2 = com.esri.core.internal.util.b.a(graphic.getAttributeValue(this.K.getEditDateField()));
            }
            a2 = Long.MIN_VALUE;
        } else {
            str = this.K.getCreatorField() != null ? (String) graphic.getAttributeValue(this.K.getCreatorField()) : null;
            if (this.K.getCreationDateField() != null) {
                a2 = com.esri.core.internal.util.b.a(graphic.getAttributeValue(this.K.getCreationDateField()));
            }
            a2 = Long.MIN_VALUE;
        }
        if ((str == null || str.length() == 0) && a2 == Long.MIN_VALUE) {
            return null;
        }
        return new EditInfo(str, a2, action_type);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: com.esri.android.map.ags.ArcGISFeatureLayer$3  reason: invalid class name */
    /* loaded from: classes.dex */
    public static /* synthetic */ class AnonymousClass3 {
        static final /* synthetic */ int[] a;
        static final /* synthetic */ int[] b;
        static final /* synthetic */ int[] c;

        static {
            int[] iArr = new int[EditInfo.ACTION_TYPE.values().length];
            c = iArr;
            try {
                iArr[EditInfo.ACTION_TYPE.EDIT.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                c[EditInfo.ACTION_TYPE.CREATION.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            int[] iArr2 = new int[SELECTION_METHOD.values().length];
            b = iArr2;
            try {
                iArr2[SELECTION_METHOD.ADD.ordinal()] = 1;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                b[SELECTION_METHOD.NEW.ordinal()] = 2;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                b[SELECTION_METHOD.SUBTRACT.ordinal()] = 3;
            } catch (NoSuchFieldError unused5) {
            }
            int[] iArr3 = new int[MODE.values().length];
            a = iArr3;
            try {
                iArr3[MODE.SNAPSHOT.ordinal()] = 1;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                a[MODE.ONDEMAND.ordinal()] = 2;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                a[MODE.SELECTION.ordinal()] = 3;
            } catch (NoSuchFieldError unused8) {
            }
        }
    }

    public EditCapabilities getEditCapabilities(Graphic graphic) {
        EditCapabilities editCapabilities = new EditCapabilities();
        if (!this.B) {
            editCapabilities.a = false;
            editCapabilities.b = false;
            editCapabilities.c = false;
        } else {
            LayerServiceCapabilities capabilities = getCapabilities();
            if (capabilities.isCreateSupported() || capabilities.isUpdateSupported() || capabilities.isDeleteSupported()) {
                if (!capabilities.isCreateSupported()) {
                    editCapabilities.a = false;
                }
                if (!capabilities.isUpdateSupported()) {
                    editCapabilities.b = false;
                }
                if (!capabilities.isDeleteSupported()) {
                    editCapabilities.c = false;
                }
            }
            if (graphic != null && this.L != null) {
                String userName = getCredentials() == null ? null : getCredentials().getUserName();
                EditFieldsInfo editFieldsInfo = this.K;
                String str = editFieldsInfo != null ? (String) graphic.getAttributeValue(editFieldsInfo.getCreatorField()) : null;
                if (!this.L.isAllowOthersToUpdate()) {
                    editCapabilities.b = a(userName, str);
                }
                if (!this.L.isAllowOthersToDelete()) {
                    editCapabilities.c = a(userName, str);
                }
            }
        }
        return editCapabilities;
    }

    public boolean isAllowGeometryUpdates() {
        return this.C;
    }

    public void queryFeatures(Query query, CallbackListener<FeatureSet> callbackListener) {
        Query a2 = a(query);
        if (b(a2)) {
            b(a2, new b(callbackListener, null, true, null, true, true));
        } else {
            a(a2, new b(callbackListener, null, true, null, true, false), false);
        }
    }

    public void queryIds(Query query, CallbackListener<int[]> callbackListener) {
        Query a2 = a(query);
        if (b(a2)) {
            c(a2, callbackListener);
        } else {
            a(a2, callbackListener);
        }
    }

    private boolean b(Query query) {
        if (this.nativeHandle == 0) {
            return false;
        }
        if (this.D) {
            return true;
        }
        if (query == null || query.getTimeExtent() != null) {
            return false;
        }
        String where = query.getWhere();
        boolean z = where != null && where.length() > 0;
        boolean z2 = this.w.outFields == null || (this.w.outFields.length == 1 && "*".equals(this.w.outFields[0]));
        boolean z3 = (query.getOutSpatialReference() == null || query.getInSpatialReference() == null || query.getOutSpatialReference().equals(query.getInSpatialReference())) ? false : true;
        if (query.getInSpatialReference() != null && !com.esri.core.internal.util.d.a(query.getInSpatialReference(), getSpatialReference())) {
            z3 = true;
        }
        if (z3 || !z2 || z) {
            return false;
        }
        int i = AnonymousClass3.a[this.w.mode.ordinal()];
        if (i != 1) {
            if (i != 2 || !isInitialized() || !this.O.b.get() || z || SpatialRelationship.INTERSECTS != query.getSpatialRelationship() || query.getGeometry() == null || !(query.getGeometry() instanceof Envelope)) {
                return false;
            }
            Envelope envelope = (Envelope) query.getGeometry();
            Envelope h = h();
            if (h == null || h.isEmpty() || h.getXMax() < envelope.getXMax() || h.getYMax() < envelope.getYMax() || h.getXMin() > envelope.getXMin() || h.getYMin() > envelope.getYMin()) {
                return false;
            }
        } else if (!isInitialized() || !this.O.b.get()) {
            return false;
        } else {
            if (SpatialRelationship.INTERSECTS == query.getSpatialRelationship() && query.getGeometry() != null) {
                boolean z4 = query.getGeometry() instanceof Envelope;
            }
        }
        return true;
    }

    public ArcGISPopupInfo createPopupInfo() {
        PopupInfo popupInfo = new PopupInfo();
        popupInfo.setMaxScale(getMaxScale());
        popupInfo.setMinScale(getMinScale());
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        Field[] fields = getFields();
        if (fields != null) {
            for (Field field : fields) {
                PopupFieldInfo popupFieldInfo = new PopupFieldInfo();
                popupFieldInfo.setFieldName(field.getName());
                popupFieldInfo.setLabel(field.getAlias());
                if ((getGlobalIdField() != null && getGlobalIdField().equals(field.getName())) || (getObjectIdField() != null && getObjectIdField().equals(field.getName()))) {
                    popupFieldInfo.setEditable(false);
                    popupFieldInfo.setVisible(false);
                }
                linkedHashMap.put(field.getName(), popupFieldInfo);
            }
        }
        popupInfo.setFieldInfos(linkedHashMap);
        ArcGISPopupInfo arcGISPopupInfo = new ArcGISPopupInfo(popupInfo);
        arcGISPopupInfo.a = this.f;
        arcGISPopupInfo.setWebMapFeatureCollection(this.D);
        return arcGISPopupInfo;
    }

    public Graphic createFeatureWithTemplate(FeatureTemplate featureTemplate, Geometry geometry) {
        Map<String, Object> linkedHashMap = new LinkedHashMap<>();
        if (featureTemplate != null) {
            linkedHashMap = featureTemplate.getPrototype();
        } else if (this.G != null && this.G.length() > 0) {
            linkedHashMap.put(this.G, null);
        }
        return new Graphic(geometry, (Symbol) null, linkedHashMap);
    }

    public Graphic createFeatureWithType(FeatureType featureType, Geometry geometry) {
        FeatureTemplate[] templates = featureType.getTemplates();
        if (templates == null || templates.length <= 0) {
            return null;
        }
        return createFeatureWithTemplate(templates[0], geometry);
    }

    public boolean isTable() {
        return this.A;
    }

    public FeatureType[] getTypes() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null) {
            return null;
        }
        return layerServiceInfo.getSubTypes();
    }

    public FeatureType getType(String str) {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null) {
            return null;
        }
        return layerServiceInfo.getSubType(str);
    }

    public FeatureTemplate[] getTemplates() {
        List<FeatureTemplate> templates = this.f.getTemplates();
        if (templates == null) {
            return null;
        }
        return (FeatureTemplate[]) templates.toArray(new FeatureTemplate[0]);
    }

    public String[] getOutFields() {
        if (this.w.outFields == null) {
            return null;
        }
        return this.w.outFields;
    }

    public String getObjectIdField() {
        if (this.G == null || this.G.length() <= 0) {
            return null;
        }
        return this.G;
    }

    public String getTypeIdField() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo != null) {
            return layerServiceInfo.getTypeIdField();
        }
        return null;
    }

    public String getDisplayField() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo != null) {
            return layerServiceInfo.getDisplayField();
        }
        return null;
    }

    public String getGlobalIdField() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo != null) {
            return layerServiceInfo.getGlobalIdField();
        }
        return null;
    }

    void a(String[] strArr) {
        if (strArr == null || strArr.length < 1) {
            this.w.outFields = null;
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            arrayList.add(str.trim());
        }
        if (this.G != null && this.G.length() > 0 && !arrayList.contains(this.G) && !arrayList.contains("*")) {
            arrayList.add(this.G);
        }
        this.w.outFields = (String[]) arrayList.toArray(new String[0]);
    }

    public boolean hasAttachments() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null || this.D) {
            return false;
        }
        return layerServiceInfo.isHasAttachments();
    }

    public InputStream retrieveAttachment(int i, int i2) throws Exception {
        if (this.D) {
            throw new UnsupportedOperationException("The operation is not supported for feature collection.");
        }
        HashMap hashMap = new HashMap();
        hashMap.put("f", "json");
        return com.esri.core.internal.io.handler.a.b(getUrl() + '/' + i + "/attachments/" + i2, hashMap, n.a(getUrl(), this.credentials));
    }

    public void clear() {
        removeAll();
        Timer timer = this.F;
        if (timer != null) {
            try {
                timer.cancel();
            } catch (Exception unused) {
            }
        }
    }

    public Geometry.Type getGeometryType() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null) {
            return null;
        }
        return layerServiceInfo.getGeometryType();
    }

    Envelope h() {
        Polygon extent = getExtent();
        if (extent == null || extent.isEmpty()) {
            return null;
        }
        Envelope envelope = new Envelope();
        extent.queryEnvelope(envelope);
        return envelope;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.android.map.Layer
    public void finalize() throws Throwable {
        clear();
        super.finalize();
    }

    public LayerServiceCapabilities getCapabilities() {
        LayerServiceInfo layerServiceInfo = this.f;
        if (layerServiceInfo == null) {
            return null;
        }
        return layerServiceInfo.getCapabilities();
    }

    public ArcGISPopupInfo getPopupInfo() {
        return getPopupInfo(0);
    }

    @Override // com.esri.android.map.Layer
    public ArcGISPopupInfo getPopupInfo(int i) {
        ArcGISPopupInfo popupInfo = super.getPopupInfo(i);
        if (popupInfo != null && popupInfo.a == null) {
            popupInfo.a = this.f;
        }
        return popupInfo;
    }

    @Override // com.esri.android.map.Layer
    public void setPopupInfos(Map<Integer, ArcGISPopupInfo> map) {
        if (this.D) {
            for (Map.Entry<Integer, ArcGISPopupInfo> entry : map.entrySet()) {
                ArcGISPopupInfo value = entry.getValue();
                if (value != null && value.isWebMapFeatureCollection()) {
                    value.a = this.f;
                }
            }
        }
        super.setPopupInfos(map);
    }

    final boolean i() {
        return getWidth() > 0 && getHeight() > 0 && this.nativeHandle != 0;
    }

    @Override // com.esri.android.map.Layer
    public void recycle() {
        c();
        super.recycle();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // com.esri.android.map.Layer
    public void updateSpatialReferenceStatus(int i) {
        super.updateSpatialReferenceStatus(i);
        j();
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public void initialUpdate() {
        e();
    }

    synchronized void j() {
        if (this.N.compareAndSet(1, 2)) {
            initialUpdate();
        } else {
            this.N.compareAndSet(0, 1);
        }
    }

    int a(Graphic graphic) {
        if (this.nativeHandle == 0 || graphic == null) {
            return -1;
        }
        Geometry geometry = graphic.getGeometry();
        return nativeAddSelectedGraphic(this.nativeHandle, geometry == null ? null : GeometryEngine.geometryToEsriShape(geometry), com.esri.core.internal.util.d.a(graphic.getAttributes()));
    }

    @Override // com.esri.android.map.GraphicsLayer
    public void setGraphicVisible(int i, boolean z) {
        super.setGraphicVisible(i, z);
        Integer valueOf = Integer.valueOf(getObjectID(i, getObjectIdField()));
        if (valueOf == null || valueOf.intValue() < 0) {
            return;
        }
        if (!z) {
            if (this.J.contains(valueOf)) {
                return;
            }
            this.J.add(valueOf);
        } else if (this.J.contains(valueOf)) {
            this.J.remove(valueOf);
        }
    }

    private com.esri.core.internal.tasks.ags.c.i c(Query query) {
        com.esri.core.internal.tasks.ags.c.i iVar = new com.esri.core.internal.tasks.ags.c.i();
        iVar.a(query.getWhere());
        iVar.b(query.getText());
        iVar.a(query.getGeometry());
        iVar.a(query.getSpatialRelationship());
        iVar.c(query.getInSpatialReference());
        iVar.b(query.getOutSpatialReference());
        iVar.a(query.isReturnGeometry());
        iVar.a(query.getOutFields());
        iVar.a(query.getObjectIdsInLong());
        iVar.b(query.isReturnIdsOnly());
        iVar.a(query.getMaxAllowableOffset());
        if (isTimeAware()) {
            iVar.a(query.getTimeExtent());
        }
        return iVar;
    }

    public EditFieldsInfo getEditFieldsInfo() {
        return this.K;
    }

    public OwnershipBasedAccessControlForFeatures getOwnershipBasedAccessControlForFeatures() {
        return this.L;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public boolean isTimeAware() {
        return isInitialized() && this.f.getTimeInfo() != null;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeExtent() {
        if (isTimeAware()) {
            return this.f.getTimeInfo().getTimeExtent();
        }
        return null;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeExtent getTimeInterval() {
        return this.b;
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public void setTimeInterval(TimeExtent timeExtent) {
        this.b = timeExtent;
        if (isInitialized() && !this.O.a && timeExtent != null) {
            this.O.a = true;
        }
        refresh();
    }

    @Override // com.esri.core.map.TimeAwareLayer
    public TimeInfo getTimeInfo() {
        if (isTimeAware()) {
            return this.f.getTimeInfo();
        }
        return null;
    }

    public double getConstraintFactor() {
        return this.v;
    }

    public void setConstraintFactor(double d2) {
        if (d2 > 1.0d) {
            d2 = 1.0d;
        }
        this.v = d2;
    }

    public boolean isLastQueryExceededTransferLimit() {
        return this.t;
    }

    public void setRequeryIfExceededTransferLimit(boolean z) {
        Options options;
        LayerServiceInfo layerServiceInfo = this.f;
        String version = layerServiceInfo == null ? null : layerServiceInfo.getVersion();
        if (version == null || version.startsWith(a) || (options = this.w) == null || options.mode != MODE.ONDEMAND) {
            Log.i(com.esri.core.internal.a.a, "Exceeded transfer limit is not supported. Please ensure you are using at least ArcGIS 10.1 or later, and that you are in ONDEMAND mode.");
        } else {
            this.u = z;
        }
    }

    public boolean isRequeryIfExceededTransferLimit() {
        return this.u;
    }

    @Override // com.esri.android.map.GraphicsLayer
    public void setSelectedGraphics(int[] iArr, boolean z) {
        super.setSelectedGraphics(iArr, z);
        if (iArr == null) {
            return;
        }
        for (int i : iArr) {
            Integer valueOf = Integer.valueOf(getObjectID(i, getObjectIdField()));
            if (valueOf != null && valueOf.intValue() >= 0) {
                if (z) {
                    if (!this.H.contains(valueOf)) {
                        this.H.add(valueOf);
                    }
                } else if (this.H.contains(valueOf)) {
                    this.H.remove(valueOf);
                }
            }
        }
    }

    @Override // com.esri.android.map.GraphicsLayer
    public void clearSelection() {
        super.clearSelection();
        this.H.clear();
    }

    @Override // com.esri.android.map.GraphicsLayer
    public void removeAll() {
        super.removeAll();
        this.H.clear();
        this.I.clear();
        this.J.clear();
    }

    @Override // com.esri.android.map.GraphicsLayer
    public void removeGraphic(int i) {
        Integer valueOf = Integer.valueOf(getObjectID(i, getObjectIdField()));
        if (valueOf != null && valueOf.intValue() >= 0) {
            this.I.remove(valueOf);
            this.J.remove(valueOf);
        }
        super.removeGraphic(i);
    }

    @Override // com.esri.android.map.Layer
    public final String getQueryUrl(int i) {
        String queryUrl = super.getQueryUrl(i);
        return (queryUrl == null && getUrl() != null && getUrl().endsWith(Integer.toString(i)) && getCapabilities() != null && getCapabilities().isQuerySupported()) ? getUrl() : queryUrl;
    }

    public void setPersistedGraphics(int[] iArr, boolean z) {
        if (iArr == null) {
            return;
        }
        for (int i : iArr) {
            Integer valueOf = Integer.valueOf(getObjectID(i, getObjectIdField()));
            if (valueOf != null && valueOf.intValue() >= 0) {
                if (z) {
                    if (!this.I.contains(valueOf)) {
                        this.I.add(valueOf);
                    }
                } else if (this.I.contains(valueOf)) {
                    this.I.remove(valueOf);
                }
            }
        }
    }

    public void clearPersistedGraphics() {
        this.I.clear();
    }

    private static final void a(Renderer renderer, Field[] fieldArr) {
        if (renderer == null || fieldArr == null) {
            return;
        }
        int i = 0;
        if (renderer instanceof UniqueValueRenderer) {
            UniqueValueRenderer uniqueValueRenderer = (UniqueValueRenderer) renderer;
            int length = fieldArr.length;
            while (i < length) {
                Field field = fieldArr[i];
                if (field != null) {
                    String name = field.getName();
                    if (name.equalsIgnoreCase(uniqueValueRenderer.getField1())) {
                        uniqueValueRenderer.setField1(name);
                    } else if (name.equalsIgnoreCase(uniqueValueRenderer.getField2())) {
                        uniqueValueRenderer.setField2(name);
                    } else if (name.equalsIgnoreCase(uniqueValueRenderer.getField3())) {
                        uniqueValueRenderer.setField3(name);
                    }
                }
                i++;
            }
        } else if (renderer instanceof ClassBreaksRenderer) {
            ClassBreaksRenderer classBreaksRenderer = (ClassBreaksRenderer) renderer;
            int length2 = fieldArr.length;
            while (i < length2) {
                Field field2 = fieldArr[i];
                if (field2 != null) {
                    String name2 = field2.getName();
                    if (name2.equalsIgnoreCase(classBreaksRenderer.getField())) {
                        classBreaksRenderer.setField(name2);
                    }
                }
                i++;
            }
        }
    }
}
